<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid" %>
<rapid:override name="frame-header-style">
	<style type="text/css">
        #updateCategory {
	    width: 100px;
	    height: 30px;
	    line-height: 30px;
	    background: #009F95;
	    color: #FFFFFF;
	  text-align: center;
         }
         /*覆盖 layui*/
        .layui-input-block {
            margin:0px 10px;
        }
        .layui-table {
            margin-top: 0;
        }
        .layui-col-md4 {
            padding:10px;
        }
        .layui-col-md8 {
            padding:10px;
        }
        .layui-btn {
            margin: 2px 0!important;
        }
  </style>
</rapid:override>
<rapid:override name="frame-header-script">
 <script type="text/javascript">
		function editfun(categoryId) {
			  $.ajax({
					type : "GET",
					url : "category/updateAjax",
					async : true,
					contentType : "application/json",
					data : {categoryId : categoryId},
					success : function(data) {
						window.category = eval("("+data+")");
						$('#updateCategory').click();
						
					}
				});
		}
		console.log(category);
	</script>

</rapid:override>
<div id="updateCategory" style="display: none;"></div>
<rapid:override name="frame-content">
	<blockquote class="layui-elem-quote">
		<span class="layui-breadcrumb" lay-separator="/"> <a
			href="/admin">首页</a> <a href="/admin/category">分类列表</a> <a><cite>添加分类</cite></a>
		</span>
	</blockquote>


	<div class="layui-row">
		<div class="layui-col-md4">
			<form class="layui-form" method="post" id="myForm"
				action="category/insertSubmit">
				<div class="layui-form-item">
					<div class="layui-input-block">
						<strong>添加分类</strong>
					</div>
					<div class="layui-input-block">
						名称 <span style="color: #FF5722;">*</span> <input type="text"
							name="categoryName" placeholder="请输入分类名称" autocomplete="off"
							class="layui-input" required>
					</div>
					<br>
					<div class="layui-input-block">
						父节点 <span style="color: #FF5722;">*</span> <select
							name="categoryPid" class="layui-input" required>
							<option value="0">无</option>
							<c:forEach items="${categorylistByZero }" var="c">
								<option value="${c.categoryId }">${c.categoryName }</option>
							</c:forEach>

						</select>
					</div>
					<br>
					<div class="layui-input-block">
						分类描述 <input type="text" name="categoryDescription"
							placeholder="请输入分类描述" autocomplete="off" class="layui-input">
					</div>
					<br>
					<div class="layui-input-block">
						图标样式 <input type="text" name="categoryIcon"
							placeholder="请输入图标样式,如 fa fa-coffee" autocomplete="off"
							class="layui-input">
					</div>
					<br>
					<div class="layui-input-block">
						<button class="layui-btn" lay-filter="formDemo" type="submit">添加</button>
					</div>
				</div>
			</form>
		</div>
		<div class="layui-col-md8">
			<table class="layui-table">
				<colgroup>
					<col width="300">
					<col width="100">
					<col width="100">
					<col width="100">
					<col width="50">
					<col width="50">
				</colgroup>
				<thead>
					<tr>
						<th>名称</th>
						<th>文章数</th>
						<th>操作</th>
						<th>ID</th>
						<th>pid</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${categorys }" var="category">
						<c:if test="${category.categoryPid == 0}">
							<tr>
								<td><a href="/category/${category.categoryId }"
									target="_blank">${category.categoryName }</a></td>
								<td><a href="/category/${category.categoryId }"
									target="_blank">${category.articleCount }</a></td>
								<td><a class="layui-btn layui-btn-mini"
									onclick="editfun(${category.categoryId})">编辑</a> <c:if
										test="${category.articleCount == 0 }">
										<a href="category/delete/${category.categoryId }"
											class="layui-btn layui-btn-danger layui-btn-mini"
											onclick="return confirmDelete()">删除</a>
									</c:if></td>

								<td>${category.categoryId }</td>
								<td>${category.categoryPid }</td>
							</tr>
							<c:forEach items="${categorys }" var="category2">
								<c:if test="${category2.categoryPid == category.categoryId }">
									<tr>
										<td><a href="/category/${category2.categoryId }"
											target="_blank">——${category2.categoryName }</a></td>
										<td><a href="/category/${category2.categoryId }"
											target="_blank">${category2.articleCount }</a></td>
										<td><a class="layui-btn layui-btn-mini"
											onclick="editfun(${category2.categoryId })">编辑</a> <c:if
												test="${category2.articleCount == 0 }">
												<a href="category/delete/${category2.categoryId }"
													class="layui-btn layui-btn-danger layui-btn-mini"
													onclick="return confirmDelete()">删除</a>
											</c:if></td>
										<td class="cate-parent">${category2.categoryId }</td>
										<td>${category2.categoryPid }</td>
									</tr>

								</c:if>
							</c:forEach>
						</c:if>
					</c:forEach>
				</tbody>
			</table>
			<blockquote class="layui-elem-quote layui-quote-nm">
				温馨提示：
				<ul>
					<li>分类最多只有两级，一级分类pid=0，二级分类pid=其父节点id</li>
					<li>如果该分类包含文章，将不可删除</li>
				</ul>
			</blockquote>
		</div>
	</div>
</rapid:override>
<rapid:override name="frame-footer-script">
	<script type="text/javascript">
$("#updateCategory").on("click", function() {
    layer.open({
        type : 2,
        title : '编辑',
        area : [ '500px', '500px' ],
        fix : false, //
        content : 'jsp/Category/category-update.jsp',
        end : function() {
            dataTable.reloadTable();
        }
    });
});
    </script>
</rapid:override>
<%@ include file="../framework.jsp"%>